<template>
  <div >
    <!-- 添加或修改订单地址对话框 -->
    <el-dialog title="选择地址" :visible.sync="open" width="40%" append-to-body>

      <el-table v-loading="loading" :data="addressList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="用户" align="center" prop="userName" />
        <el-table-column label="电话" align="center" prop="userTelephone" />
        <el-table-column label="区域" align="center" prop="area" />
        <el-table-column label="详细地址" align="center" prop="detail" />

      </el-table>

      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />



      <div slot="footer" class="dialog-footer" style="text-align:center;">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listAddress, getAddress, delAddress, addAddress, updateAddress, exportAddress } from "@/api/order/address";

export default {
  name: "Address",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      selection: [],
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 订单地址表格数据
      addressList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userName: null,
        userTelephone: null,
        area: null,
        arearCode: null,
        detail: null,
        x: null,
        y: null,
        userId: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    init(){
      this.open = true;
    },
    /** 查询订单地址列表 */
    getList() {
      this.loading = true;
      listAddress(this.queryParams).then(response => {
        this.addressList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        userName: null,
        userTelephone: null,
        area: null,
        arearCode: null,
        detail: null,
        x: null,
        y: null,
        userId: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.selection = selection
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 提交按钮 */
    submitForm() {
      if (this.single ) {
        this.msgError("请选择一条记录");
        return;
      }
      this.open = false;
      this.$emit("finishSelected", this.selection[0]);
    },

    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },

  }
};
</script>
